package com.kly.sc.api.application.controller.product.response;

import com.alibaba.fastjson.JSONObject;
import com.fqgj.common.utils.CollectionUtils;
import com.kly.dto.ProductBenefitDto;
import com.kly.sc.api.infras.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@ApiModel("新手礼包弹窗")
public class WelcomePackPopVO {
    @ApiModelProperty(value = "顶部轮播图")
    private List<CarouselImg> carousel;
    @ApiModelProperty(value = "折扣标签")
    private String discountTag;
    @ApiModelProperty(value = "标题")
    private String title;
    @ApiModelProperty(value = "小字")
    private String subtitle;
    @ApiModelProperty(value = "会员卡片")
    private MemberInfo memberInfo;
    @ApiModelProperty(value = "赠送PP卡片")
    private BenefitsInfo benefitsInfo;
    @ApiModelProperty(value = "新手价")
    private String newcomerPrice;
    @ApiModelProperty(value = "正常价")
    private String normalPrice;
    @ApiModelProperty(value = "小字说明")
    private String notice;
    @ApiModelProperty(value = "底部支付相关注释，支持底部区域文案上下滑动")
    private PayInfo payInfo;
    @ApiModelProperty(value = "谷歌商品ID")
    private String productCode;
    @ApiModelProperty(value = "商品分类")
    private Integer productCategory;
    @ApiModelProperty(value = "背景图片")
    private String backgroundImg;

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel("顶部轮播图")
    public static class CarouselImg {
        @ApiModelProperty(value = "头像")
        private String img;
        @ApiModelProperty(value = "标题")
        private String title;
        @ApiModelProperty(value = "文案")
        private String content;

        public static List<CarouselImg> from(List<ProductBenefitDto> productBenefitList) {
            if (CollectionUtils.isEmpty(productBenefitList)) {
                return Collections.emptyList();
            }

            return productBenefitList.stream()
                    .map(o -> {
                        final String benefitDesc = o.getBenefitDesc();
                        if (StringUtils.isNotEmpty(benefitDesc)) {
                            final JSONObject benefit = JSONObject.parseObject(o.getBenefitDesc());
                            return CarouselImg.builder().title(o.getTip()).content(o.getContent()).img(benefit.getString("icon")).build();

                        }
                        return null;
                    })
                    .collect(Collectors.toList());
        }
    }

    @Getter
    @Setter
    @ApiModel("会员卡片")
    public static class MemberInfo {
        @ApiModelProperty(value = "价格")
        private String price;
        @ApiModelProperty(value = "小字部分")
        private String remark;
    }

    @Getter
    @Setter
    @ApiModel("赠送PP卡片")
    public static class BenefitsInfo {
        @ApiModelProperty(value = "图片")
        private String icon;
        @ApiModelProperty(value = "数量")
        private String num;
        @ApiModelProperty(value = "名称")
        private String name;
    }

    @Getter
    @Setter
    @ApiModel("底部支付相关注释，支持底部区域文案上下滑动")
    public static class PayInfo {
        @ApiModelProperty(value = "标题")
        private String title;
        @ApiModelProperty(value = "文案")
        private String content;
    }
}
